function selectCourse(btn) {
    swal({
        title: "选课确认",
        text: "是否确认选择当前课程？\n如想修改选课信息，请前往查看已选课程页面",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#1ab394",
        confirmButtonText: "确认选课",
        cancelButtonText: "取消选课",
        closeOnCancel: false,
        closeOnConfirm: true
    }, function (isConfirm) {
        if (isConfirm) {
            $(btn).prev().click()
        } else {
            swal("已取消", "您取消了删除操作！", "error");
        }
    });
}

function deleteCourse(btn) {
    swal({
        title: "退课确认",
        text: "是否确认取消选择当前课程？\n取消后可继续选择其他课程",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#b31a1a",
        confirmButtonText: "确认退课",
        cancelButtonText: "取消退课",
        closeOnCancel: false,
        closeOnConfirm: true
    }, function (isConfirm) {
        if (isConfirm) {
            $(btn).prev().click()
        } else {
            swal("已取消", "您取消了删除操作！", "error");
        }
    });
}

function deleteStudent(btn) {
    swal({
        title: "确定删除？",
        text: "是否确定删除此学生？\n删除后不可恢复",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#b31a1a",
        confirmButtonText: "确认删除",
        cancelButtonText: "取消删除",
        closeOnCancel: false,
        closeOnConfirm: true
    }, function (isConfirm) {
        if (isConfirm) {
            $(btn).prev().click()
        } else {
            swal("已取消", "您取消了删除操作！", "error");
        }
    });
}


/*验证工号或者学号*/
function checkId() {
    var id = $(".id").val();
    var regId = /^[0-9]{11}$/;// ，接11位数字
    var regId2 = /^[0-9]{6}$/;// ，接11位数字
    if (id == "" || regId.test(id) || regId2.test(id)) {
        return true;
    } else {
        swal({
            title: "错误",
            text: "您输入的学号/工号不正确，请检查后重新输入",
            type: "warning",
            confirmButtonColor: "#e58410"
        });
        $(".id").val("");
    }
}

/* 验证密码 */
function checkPassword() {
    var password = $(".password").val();
    var regPassword = /(?=.*([a-zA-Z].*))(?=.*[0-9].*)[a-zA-Z0-9-*/+.~!@#$%^&*()]{6,20}$/;// 至少包含数字跟字母，可以有字符，长度6-20
    if (password = "" || regPassword.test(password)) {
        return true;
    } else {
        swal({
            title: "密码格式错误",
            text: "您输入的密码格式不正确，请至少包含数字跟字母，可以有字符，长度6-20。",
            type: "warning",
            confirmButtonColor: "#e58410"
        });
        $(".password").val("");
    }
}

/* 两次密码是否一致 */
function checkSame() {
    var password = $(".password").val();
    var rePassword = $(".rePassword").val();
    if (password != rePassword) {
        swal({
            title: "错误",
            text: "您两次输入的密码不一致，请检查后输入。",
            type: "warning",
            confirmButtonColor: "#e58410"
        });
        $(".rePassword").val("");
    } else {
        return true;
    }
}

/*验证工号或者学号*/
function checkStudentId() {
    var id = $(".id").val();
    var regId = /^[0-9]{11}$/;// 11位数字
    if (id == "" || regId.test(id)) {
        return true;
    } else {
        swal({
            title: "错误",
            text: "您输入的学号不正确，请检查后重新输入",
            type: "warning",
            confirmButtonColor: "#e58410"
        });
        $(".id").val("");
    }
}

/* 验证用户姓名 */
function checkName() {
    var name = $(".name").val();
    var regName = /^([\u4e00-\u9fa5]{1,20}|[a-zA-Z\.\s]{1,20})$$/;
    //	var regName = /(^(?:[\u4e00-\u9fa5]+)(?:●[\u4e00-\u9fa5]+)*$|^[a-zA-Z]+\s?[\.·\-()a-zA-Z]*[a-zA-Z]+$)|(^$|^\d+)$/;
    /*
     * 中文姓名长度 ≥ 2个字符，≤ 200个字符。可包含汉字、“●”。 字符间距不支持空格，不允许有“●”以外的其他特殊字符，不允许有数字。
     * 英文姓名长度 ≥ 1个字符，≤200个字符。可包含字母、括号、字符间支持一个空格、“.”、“●”、“-”
     */
    if (name = "" || regName.test(name)) {
        return true;
    } else {
        swal({
            title: "错误",
            text: "您输入的姓名格式不正确，请检查后重新输入。",
            type: "warning",
            confirmButtonColor: "#e58410"
        });
        $(".name").val("");
        return false;
    }
}

/* 验证手机号码 */
function checkPhone() {
    var phone = $(".phone").val();
    var regPhone = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
    if (phone == "" || regPhone.test(phone)) {
        return true;
    } else {
        swal({
            title: "错误",
            text: "您输入的手机号不正确，请检查后重新输入。",
            type: "warning",
            confirmButtonColor: "#e58410"
        });
        $(".phone").val("");
        return false;
    }
}

/**
 * 登陆界面
 * 验证是否全部输入
 * @param btn
 */
function checkLoginInfo(btn) {
    var id = $(".id").val();
    var password = $(".password").val();
    if (id == "" || password == "") {
        swal({
                title: "错误",
                text: "请仔细检查，将信息输入完整",
                confirmButtonColor: "#e58410"
            },
            function () {
                window.location.href = "../../student_select_course/login.xhtml"
            });
    } else {
        $(btn).prev().click()
    }
}


/**
 * 修改密码界面
 * 验证是否全部输入
 * @param btn
 */
function checkModifyPassword(btn) {
    var id = $(".id").val();
    var password = $(".password").val();
    var oldPassword = $(".oldPassword").val();
    var rePassword = $(".rePassword").val();
    if (id == "" || password == "" || oldPassword == ""||rePassword == "") {
        swal({
                title: "错误",
                text: "请仔细检查，将信息输入完整",
                confirmButtonColor: "#e58410"
            },
            function () {
                window.location.href = "../../student_select_course/modify_password.xhtml"
            });
    } else {
        $(btn).prev().click()
    }
}

/**
 * 重置密码界面
 * 验证是否全部输入
 * @param btn
 */
function checkRetrievePassword(btn) {
    var id = $(".id").val();
    var password = $(".password").val();
    var phone = $(".phone").val();
    var rePassword = $(".rePassword").val();
    if (id == "" || password == "" || phone == ""||rePassword == "") {
        swal({
                title: "错误",
                text: "请仔细检查，将信息输入完整",
                confirmButtonColor: "#e58410"
            },
            function () {
                window.location.href = "../../student_select_course/retrieve_password.xhtml"
            });
    } else {
        $(btn).prev().click()
    }
}

/**
 * 初始化密码界面
 * 验证是否全部输入
 * @param btn
 */
function checkInitPassword(btn) {
    var password = $(".password").val();
    var rePassword = $(".rePassword").val();
    if (password == ""||rePassword == "") {
        swal({
                title: "错误",
                text: "请仔细检查，将信息输入完整",
                confirmButtonColor: "#e58410"
            },
            function () {
                window.location.href = "../../student_select_course/init_password.xhtml"
            });
    } else {
        $(btn).prev().click()
    }
}
